package com.totcy.atom.view.activity;

import android.content.Intent;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;

import com.totcy.atom.R;
import com.totcy.atom.bean.User;
import com.totcy.atom.bean.response.VoidResponse;
import com.totcy.atom.presenter.RegisterPresenter;
import com.totcy.atom.presenter.contract.RegisterContract;
import com.totcy.baselibrary.utils.ToastUtil;
import com.totcy.baselibrary.widget.ProgressCircleView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 注册
 */
public class RegisterActivity extends BaseFullActivity<RegisterContract.View, RegisterPresenter> implements RegisterContract.View {

    @BindView(R.id.et_account)
    EditText etCount;
    @BindView(R.id.password)
    EditText etPassword;
    @BindView(R.id.passwordAgain)
    EditText etPasswordAgain;
    public static int REQUEST_CODE_REGISTER = 100;


    @Override
    public boolean isChildLayoutBelowTitle() {
        return false;
    }

    @Override
    public String getTitleName() {
        return getString(R.string.action_register);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    public void initView() {
        setToolbarTitleLayoutBackground(R.color.transparent);


    }

    @OnClick({R.id.btn_register})
    public void onViewClick(View view) {
        if (TextUtils.isEmpty(etCount.getText())) {
            etCount.setError(getString(R.string.count_is_not_null));
            return;
        }

        if (TextUtils.isEmpty(etPassword.getText())) {
            etPassword.setError(getString(R.string.password_is_not_null));
            return;
        }
        if (!(etPassword.getText().toString().equals(etPasswordAgain.getText().toString()))) {
            etPasswordAgain.setError(getString(R.string.password_invalid));
            return;
        }
        etCount.setError(null);
        etPassword.setError(null);
        etPasswordAgain.setError(null);

        Map<String, Object> params = new HashMap<>();
        params.put("user_login", etCount.getText().toString());
        params.put("user_pass", etPassword.getText().toString());
        params.put("user_nicename", etCount.getText().toString());

        showProgress("");
        getPresenter().doRegister(params);
    }

    @Override
    public void onRegisterResult(User response) {
        dismissProgress();
        ToastUtil.showToast(this, R.string.register_success);
        setResult(RESULT_OK, new Intent().putExtra("userInfo", response));
        finish();
    }

    @Override
    public void onRegisterFail(String message) {
        dismissProgress();
        showDialogTips(message);
    }
}
